capture log close
log using replica_fig2_nocomp_2.log,replace


*       FIG_NOCOMP_2.LOG

*       FIRST VERSION   JUNE 20, 2006
*       THIS VERSION    AUGUST 2, 2012

*       LAST REVISOR    AI

*       INPUT FILE:             BASE12_6.DTA
*       OUTPUT FILE:            ANALYSIS NO COMP
*
*
*		REPLICA FOR FIGURE 2

version 9.0

di "log file printed on $S_DATE at $S_TIME"


set more 1
clear
program drop _all
macro drop _all
scalar drop _all

# delimit ;

set scheme s1color;
set memory 300000; 
set matsize 250;
tempfile tmpf1 tmpf2 tmpf3 tmpf4;

use base12_6, clear;

* KEEP MEDIA PRIMO ANNO;
sort id anac;
qui by id: gen gpa_1 = gpa[1]; 

* lagged income and taxes;
gen ym1 = l1.y;
gen ydm1 = l1.yd;
gen tteom1 = l1.tteo;
gen tpaidm1 = l1.tpaid;

gen ym2 = l2.y;
gen ydm2 = l2.yd;
gen tteom2 = l2.tteo;
gen tpaidm2 = l2.tpaid;

gen ym3 = l3.y;
gen ydm3 = l3.yd;
gen tteom3 = l3.tteo;
gen tpaidm3 = l3.tpaid;



* SELEZIONE DEL CAMPIONE;
* keep studenti in corso regolare al 4 anno;
keep if real_status==4&aniscr==4&posizione==14 ;

xtdes;

*******NEW
* restrizione della distanza dalla soglia;
keep if yd>-3&yd<3;

xtdes;





* VARIABILI NECESSARIE;

tab anac, gen(daa);

gen y2 = y*y;
gen y3 = y*y2;
gen y4 = y*y3;

label var y "Real income - thousands of Euros, base 2000";

tab fascia_teo, gen(dfa);

gen yd2 = yd*yd;
gen yd3 = yd2*yd;
gen yd4 = yd3*yd;

label var yd "Distance from nearest discontinuity in 1000 euros";


* ALTRE VARIABILI NECESSARIE PER ANALISI  RDD;


*generate for compliance analysis;
gen comp = tpaid>=tteo1;
label var comp "fraction with tpaid >tteo1";

* generate dummies for nearest discontinuity;
tab neardisc , gen(dnear);

* calcola gli scarti dalla media di anno/punto di discontinuit�

sort anac neardisc;
egen mtp=mean(tpaid), by(anac neardisc);
gen wtp=tpaid-mtp;
label var wtp "paid tuition in deviation from mean";



* VARIABILI PRE INTERVENTION;

* Normalizzazione del voto di matematica;
gen normat = (mat - 0)/(31-0);
sum normat votodip;
corr normat votodip;

* Normalizzazione del voto di statistica;
gen norsta = (sta - 0)/(31-0);
sum norsta votodip;
corr norsta votodip;

* Normalizzazione del gpa 1 anno;
gen norgpa1 = (gpa_1 - 0)/(31-0);
sum norgpa1 votodip;
corr norgpa1 votodip;

* generate dummy liceo from  tipo diploma;
gen typedip =  cod_tit_dipl ==1 ;


* altre variabili da usare nelle regressioni

outmil
female
votodip

;



# delimit cr




* analisi per soglia

local c = 1
di `c'

forvalues i=2(5)7 {
di "regressioni per soglia " `i'


local cp1 = `c' + 1
di" c = "  `c'
di" cp1 = "  `cp1'



* istogramma distribuzione tpaid around tteo

gen tpaid_l`i' =round((tpaid),0.1) if yd<0&neardisc==`i'&anac==1998
label var tpaid_l`i' "Tuition paid by those with low official tuition"
gen tpaid_h`i' =round((tpaid),0.1) if yd>0&neardisc==`i'&anac==1998
label var tpaid_h`i' "Tuition paid by those with high official tuition"

gen tteo_l`i' = round((tax_teo`i'/cpi),0.1)
sum tteo_l`i'
local tteo_l = round(r(mean),0.1)
di " tteolow at `i' " `tteo_l'
tab tpaid_l`i'

local ip1 = `i'+1
gen tteo_h`i' = round((tax_teo`ip1'/cpi),0.1)
sum tteo_h`i'
local tteo_h = round(r(mean),0.1)
di " tteohigh at `i' " `tteo_h'
tab tpaid_h`i'

twoway ( hist tpaid_l`i', discrete color(black)  percent  width(0.04) /*gap(50)*/ ) if neardisc==`i' , xmlabel(`tteo_l', labs(medium)) ylabel(0(10)60)  xlabel(0(2)6) xline(`tteo_l', lwidth(2) lcolor(gs10)) title("Left of Discontinuity `i'" ) saving(tp_l`i', replace) 

twoway ( hist tpaid_h`i', discrete color(black) percent width(0.04) /*gap(50)*/) if neardisc==`i' ,  xmlabel(`tteo_h', labs(mediuml))ylabel(0(10)60)  xlabel(0(2)6) xline(`tteo_h', lwidth(2) lcolor(gs10)) title("Right of Discontinuity `i'" ) saving(tp_h`i', replace)



}



* grafici finali combinati

* figura a quattro pannelli tpaid around tteo
gr combine tp_l2.gph tp_l7.gph tp_h2.gph tp_h7.gph ,  b1title("The light bars indicate the assigned official tuitions", size(small)) saving(tptt_4p, replace)
*graph export fin_tptt_4p.eps, replace logo(off)
graph export fig_2.eps, replace logo(off)




log close






